<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="css/form.css" />
</head>

<body>
	<div id="header-wrap" data-mn=0 data-limit=2>
		<a href="###" data-link="account" data-type="ico" class="left ico-m ico-left"></a>
		<h2>提现</h2>
		<a href="###" data-link="tariff" class="right btn b-small b-red">说明</a>
	</div>
	<div class="" id="">
		<div class="tips">
			<div class="t-info">可提现金额 <b id="balance"></b>元</div>
			<div class="t-error"></div>
		</div>
		<form>
		<ul class="form-list c-right" id="">
			<li class="ico-m ico-pl ico-red ico-rmb" data-type="ico">
				<div class="fl-cont form-input">
					<input type="number" id="tx" placeholder="请输入提现金额" value="" />
				</div>
			</li>
			<li class="ico-m ico-pl ico-change" data-type="ico">
				<div class="fl-cont form-input">
					手续费：<span id="shouxufei"></span>元
					<label style="position:absolute;line-height:32px;height:32px;right:10px;top:2px;padding:0 38px 0 0">免费提现<input style="position:absolute;top:0;right:0;width:32px;height:32px;" type="checkbox" id="free_tx" /></label>
				</div>
			</li>
			<li class="ico-m ico-pl ico-ok" data-type="ico">
				<div class="fl-cont form-input">
					实际到账：<span id="dz"></span>
				</div>
			</li>
		</ul>
		<div class="fixed-btn">
			<a href="###" data-link="extract-1" class="btn b-red"><span id="check">提现</span></a>
		</div>
		<div id="bank-card">
			<div class="card-wrap">
				<span class="bico-gongshangyinhang" ></span>
				<h3 id="">中国工商银行借记卡</h3>
				<b id="card_code"></b>
				<em id="card_name"></em>
			</div>
		</div>
		</form>
		<div class="feed-info">
			<h2>如有疑问，请咨询...</h2>
			客服电话：400-105-8851<br />
			微信客服：wuyifugui(公众号)
		</div>
	</div>
	<script>
	$(function(){
		var free_t = $.cookie("free_t");
		if(free_t == undefined){
			$.cookie("free_t",5);
			free_t = 5
		}else{
			free_t = parseInt(free_t);
			if(free_t < 1){
				$("#free_tx").remove();
			}
		}
		var balance = Number($.cookie("balance"));
		var balance_show = Number($.cookie("balance")).toFixed(2);
		$("#balance").text(balance_show)
		var bind_card = $.cookie("bcard");
		if(bind_card == undefined ){
			alert("请先绑定一张银行卡")
			load_page("edit-bcard")
		}else if(balance <2){
			$(".t-error").text("余额不足").fadeIn(100)
			$(".t-info").hide();
			return false
			
		}else{
			var bcard = $.cookie("bc_show");
			var name = $.cookie("name_show");
			$("#card_code").text(bcard);
			$("#card_name").text(name);
			$.cookie("tx_sxf",2)
			var shouxufei = Number($.cookie("tx_sxf")).toFixed(2);
			$("#shouxufei").text(shouxufei)
		
			$("#tx").on("keyup",function(){
				var val = parseInt($(this).val(),10)
				$(this).val(val);
				val = $(this).val();
				if(isNaN(val[0])){
					$("#dz").text("0元")
				}else{
					var out = 0;
					if(!$("#free_tx").is(":checked")){
						out = val-2;
						if(out < 0){
							$("#dz").text("0元")
						}else{
							$("#dz").text((val-2)+"元")
						}
					}else{
						$("#dz").text(val+"元")
					}
					
				}
			})
			$("#free_tx").on("click",function(){
				var val = $("#tx").val();
				var out;
				if($(this).is(":checked")){
					out = $("#tx").val();
					if(isNaN(out[0])){
						$("#dz").text("0元")
					}else{
						$("#dz").text(out+"元")
					}
				}else{
					out = $("#tx").val()-2;
					if(out < 0){
						$("#dz").text("0元")
						$("#tx").val("")
					}else{
						$("#dz").text(out+"元")
					}
				}
			})
			$("#check").on("click",function(){
				var tx = $("#tx").val();
				var tx_return = $("#tx").check({type:8});
				if(tx == ''){
					$(".t-error").text("提现金额不能为空").fadeIn(100)
					$(".t-info").hide();
					reset_tip()
					return false
				}else if(tx < 3 && !$("#free_tx").is(":checked")){
					$(".t-error").text("提现不能金额小于手续费（2.00元）\n您可以使用免费提现券").fadeIn(100)
					$(".t-info").hide();
					reset_tip()
					return false
				}
				if (tx_return == 0){
					$(".t-error").text("请输入有效金额").fadeIn(100)
					$(".t-info").hide();
					reset_tip()
					return false
				}else{
					if($("#free_tx").is(":checked")){
						free_t -= 1;
					}
					if(tx > balance){
						$(".t-error").text("提现超额，最多可提现 "+balance+" 元").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}else{
						balance -= tx
					}
					alert(balance)
					$.cookie("tx_temp",tx);
					$.cookie("balance_temp",balance);
					$.cookie("free_t_temp",free_t);
				}
			})
		}
	})
	</script>	
</body>

</html>
